package corp.edu.amadeus.web.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import corp.edu.amadeus.core.business.object.impl.FileBO;
import java.util.Collection;
import org.apache.log4j.Logger;
import java.io.File;
import corp.edu.amadeus.core.business.service.ifc.IFileService;
import corp.edu.amadeus.core.business.locator.ServiceLocator;

public class FileAction extends ActionSupport {

	private static Logger log = Logger.getLogger(FileAction.class);
	private Collection<FileBO> filesList;
	private IFileService fileService;
	private Integer id;

	private File upload;//The actual file
    private String uploadContentType; //The content type of the file
    private String uploadFileName; //The uploaded file name

    private String description;//The description of the file entered by user
    private String lang;

	public FileAction() {
		this.fileService = ServiceLocator.getFileService();
		this.filesList = this.fileService.getAllFiles();
	}

	public void setFilesList(Collection<FileBO> f) { this.filesList = f; }
	public Collection<FileBO> getFilesList() { return this.filesList; }

	public String execute() throws Exception {
		this.filesList = this.fileService.getAllFiles();
    	return SUCCESS;
    }

	public String save() throws Exception {
		log.debug("Saving text data.");
		if(this.id!=null) {

		} else {
			this.fileService.addFile(this.upload, this.uploadFileName, lang, this.description);
		}
		return this.execute();
	}

	public String list() throws Exception {
		return this.execute();
	}

	public String remove() throws Exception {
		return this.execute();
	}

	public Integer getId() { return this.id; }
	public void setId(Integer i) { this.id = i; }

	public File getUpload() { return upload; }
	public void setUpload(File upload) { this.upload = upload; }

	public String getUploadContentType() { return uploadContentType; }
	public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; }

	public String getUploadFileName() { return uploadFileName;}
	public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; }

	public String getDescription() { return this.description; }
	public void setDescription(String d) { this.description = d; }

	@RequiredStringValidator(message = "Por favor, introduzca el idioma", trim = true)
	public void setLang(String l) { this.lang = l; }
	public String getLang() { return this.lang; }

}